#include "userconfigmanager.h"

UserConfigManager::UserConfigManager(QObject *parent)
    : QObject(parent)
{
}

bool UserConfigManager::copyUser(const QString &srcUser,const QString &newUser, QString &errorMsg)
{
    JsonConfigWriter writer;

    // 不能拷贝到自己
    if (srcUser == newUser) {
        errorMsg = QObject::tr("The new user is the same as the original user.");
        return false;
    }

    // 读取原用户配置
    QStringList hiddenCtrls;
    if (!writer.Read_Json_To_Ui(srcUser, hiddenCtrls)) {
        errorMsg = QObject::tr("Failed to read the original user configuration.");
        return false;
    }

    // 写入新用户配置
    if (!writer.Write_To_Ui_Json(newUser, hiddenCtrls)) {
        errorMsg = QObject::tr("Failed to save the new user configuration.");
        return false;
    }

    // 发信号通知 UI
    emit userCopied(newUser);
    return true;
}
